<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="https://v3.bootcss.com/favicon.ico">
<title>文章添加</title>
<link href="/css/bootstrap/bootstrap.min.css" rel="stylesheet">
<link href="/css/page/blog.css" rel="stylesheet">
<link href="/css/markdown/simplemde.min.css" rel="stylesheet">
<link href="/css/font-awesome.min.css" rel="stylesheet">
</head>

<body>

	<#include "/nav.ftl"/>

	<div class="container">
		<div class="row" style="padding-top: 20px">
			<form class="form-horizontal" id="form_save">
				<div class="form-group">
					<label for="ipt_title" class="col-sm-2 control-label">标题</label>
					<div class="col-sm-10">
						<input type="text" maxlength="20" name="title" class="form-control notEmpty" id="ipt_title" placeholder="标题">
					</div>
				</div>
				<div class="form-group">
					<label for="ipt_brief " class="col-sm-2 control-label">简介</label>
					<div class="col-sm-10">
						<input type="text" maxlength="30" name="brief" class="form-control notEmpty" id="ipt_brief" placeholder="简介">
					</div>
				</div>
				<div class="form-group">
					<label for="ipt_brief " class="col-sm-2 control-label">内容</label>
					<div class="col-sm-10">
						<textarea id="textarea_content" name="content" class="form-control"></textarea>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="button" onclick="save()" class="btn btn-default">保存</button>
					</div>
				</div>
			</form>
		</div>
		<!-- /.row -->

	</div>
	<!-- /.container -->
	<#include "/foot.ftl"/>
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/bootstrap/bootstrap.min.js"></script>
	<script type="text/javascript" src="/js/bootstrap/plugins/bootbox.js"></script>
	<script type="text/javascript" src="/js/common/common.js"></script>
	<script type="text/javascript" src="/js/common/myValidation.js"></script>
	<script type="text/javascript" src="/js/markdown/simplemde.min.js"></script>
	<script type="text/javascript">
			var simplemde = new SimpleMDE({
				element: $("#textarea_content")[0],
				autoDownloadFontAwesome:false,
				spellChecker: false
			});
			function save(){
				var validResult = myValidation.commonValid("form_save", {
					showInfo : function(ele, mes) {
						bootbox.alert(mes);
					}
				});
				if (!validResult) {
					return;
				}
				var content = simplemde.value();
				if(content.trim().length == 0){
					bootbox.alert("请输入内容");
				}
				$("#textarea_content").val(content);
				$.post("/article/add",$("#form_save").serialize(), function(result){
					if(result.code == 200){
						bootbox.alert("添加成功", function(){
							location.href= "/";
						});
					}else{
						bootbox.alert(result.mes);
					}
				})
			}
		
		</script>
</body>

</html>